<?php
namespace app\fruit\controller;
use app\common\Base;
use think\Db;

class StudentFruitQuery extends Base {
	
	public function index() {
		return $this->fetch();
	}

	public function pageQuery() {
		$where = [];
		$termId = input("termId");
		$grade = input("grade");
		$level = input("获奖级别");
		$rank = input("获奖等第");
		$studentName = input("studentName");
		$page = input("page");
		$rows = input("rows");
		if($termId) $where["学期ID"] = $termId;
		if($grade) $where["年级"] = $grade;
		if($level) $where["获奖级别"] = $level;
		if($rank) $where["获奖等第"] = $rank;
		if($studentName) $where["姓名"] = array("like",$studentName);
		$result = Db::table('学生成果')->alias('a')
				  ->join('学期名称 b','a.学期ID = b.ID','LEFT')
				  ->join('学生信息 c','a.学生ID=c.ID','LEFT')
				  ->field("a.ID,a.竞赛名称,a.参赛组别,a.参赛子项目,a.作品名称,a.年级,a.班别,a.获奖级别,a.获奖等第,a.获奖时间,a.授奖单位,a.指导教师,a.加分,a.备注,a.学期ID,a.学生ID,b.学期名称,c.姓名")
				  ->where($where)
				  ->order("学期ID desc,ID desc")
				  ->page($page, $rows)
		          ->select();
		$count = Db::table('学生成果')->alias('a')
				  ->join('学期名称 b','a.学期ID = b.ID','LEFT')
				  ->join('学生信息 c','a.学生ID=c.ID','LEFT')
				  ->where($where)
				  ->count();
		$grid['rows'] = selectResult($result);
        $grid['total'] = $count;
		return $grid;
	}

}
